<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<head>
<!--添加弹层效果和layui-->
<script type="text/javascript" src="<%=jsPath%>/layer/layer.js"></script>

<script>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var displayOption= new Array();//定义显示类型
    //加载
    $(document).ready(function () {
        
        //设置默认处理内容
        setProcessText();

        //单选按钮点击事件
        $("#processedTypeTd").click(function(){
            var value1 = $('input[name="releaseType"]:checked').val();
            if (value1 == "文本下发"){
                $("#sendDisplayTr").css("display","table-row");
                $("#releaseTextArea").css("height","110px");
                $("#textFlgTd").html("发送内容：");
            }else{
                $("#sendDisplayTr").css("display","none");
                $("#releaseTextArea").css("height","147px");
                $("#textFlgTd").html("处理描述：");
            }
            setProcessText();
        });

        //按钮点击事件
        $("#releaseAlarmBtn").click(function () {
            console.log("点击获取参数");
            var value1 = $('input[name="releaseType"]:checked').val();
            var value2 = $("#releaseTextArea").val();

            if (value1 == "") {
                layer.msg("请选择一种处理方式");
                return;
            }
            if (value2 == "" && value1 == '文本下发') {
                layer.msg("请输入文本信息或处理描述内容");
                return;
            }

            //传递参数
            if (value1 == "文本下发") {
                //发送文本处理方式
                parent.$("#formParam1").val(value2);
                //获取显示类型
                var displayOption = new Array();
                for (var i = 0; i < 5; i++) {
                    if (i != 1) {
                        if ($("#ckDisplay" + i).attr("checked") != undefined) {
                            displayOption.push($("#ckDisplay" + i).val());
                        }
                    }
                }
                //校验选择类型
                if (displayOption.length == 0) {
                    layer.msg("请选择显示类型");
                    return;
                }
                //设置参数
                parent.$("#formParam2").val(displayOption);
            } else {
                //报警处理方式
                var strTemp = value1 + ":" + value2;
                parent.$("#formParam1").val(strTemp);
            }

            parent.layer.close(index);//关闭弹窗
            if(value1 == "文本下发"){
                parent.processedAlarmAction("send");//父页面方法
            }else{
                parent.processedAlarmAction("processed");//父页面方法
            }
            
        });
    });


    //设置默认的处理内容
function setProcessText(){
    //输出报警
    // console.log("开始测试输出报警类型");
    var alarmSourceNameTemp = "";
    var alarmTypeNameTemp = "";
    if (parent) {
        if (parent.adasAlarmBasicInfo) {
            alarmTypeNameTemp = parent.adasAlarmBasicInfo.alarmTypeName;
            alarmSourceNameTemp = parent.adasAlarmBasicInfo.alarmSourceName;
        } else if (typeof (parent.getSelectedAlarmTypeName) == "function") {
            alarmTypeNameTemp = parent.getSelectedAlarmTypeName();
            alarmSourceNameTemp = parent.getSelectedAlarmSourceName();
        }
    }
    let value1 = $('input[name="releaseType"]:checked').val();//处理方式
    // console.log("报警来源为："+alarmSourceNameTemp);
    // console.log("报警类型为："+alarmTypeNameTemp);
    var processedTextTemp = Utility.getProcessText(alarmSourceNameTemp,alarmTypeNameTemp);
    // console.log("处理内容为："+processedTextTemp);
    if(processedTextTemp != undefined && value1 == '文本下发'){
        // console.log("开始填充内容："+processedTextTemp);
        $("#releaseTextArea").val(processedTextTemp);
    }else{
        $("#releaseTextArea").val('');
    }
}
</script>
</head>
<body>
    <table width="100%" class="TableBlock">
        <tbody>
            <tr>
                <td align="right">处理方式:</td>
                <td id="processedTypeTd">
                    <input id="releaseType2" type="radio" name="releaseType" value="文本下发" checked="checked"/>文本下发
                    <input id="releaseType1" type="radio" name="releaseType" value="报警解除"/>报警解除
                    <!-- <input id="releaseType3" type="radio" name="releaseType" value="误报"/>误报 -->
                    <!-- <input id="releaseType4" type="radio" name="releaseType" value="忽略"/>忽略 -->
                    <!-- <input id="releaseType5" type="radio" name="releaseType" value="其他"/>其他 -->
                </td>
            </tr>
            <tr id="sendDisplayTr">
                    <td align="right">信息显示类型:</td>
                    <td>
                        <input type="checkbox" id="ckDisplay0" name="displayOption" value="0" />紧急
                        <input type="checkbox" id="ckDisplay2" name="displayOption" value="2" checked="true"/>终端显示器显示
                        <input type="checkbox" id="ckDisplay3" name="displayOption" value="3" checked="true"/>终端TTS播读
                        <input type="checkbox" id="ckDisplay4" name="displayOption" value="4" />广告屏显示
                        <!--<input type="checkbox" id="" name="displayOption" value="5" />弗斯特广告屏-->
                    </td>
                </tr>
            <tr>
                <td id="textFlgTd" align="right">发送内容</td>
                <td>
                    <textarea id="releaseTextArea" name="releaseText" class="required" style="height:110px;" cols=40 onpropertychange="this.style.posHeight=this.scrollHeight "></textarea>
                </td>
            </tr>
            <tr>
            <td colspan=2 align="center">
                <input id="releaseAlarmBtn" type="button"  value="提交" style="width:90px;height:30px;font-size:14px;">
            </td>
            </tr>
        </tbody>
    </table>
</body>